package cn.com.cifi.mars.service.impl;

import cn.com.cifi.mars.bean.dto.OperGuideDto;
import cn.com.cifi.mars.bean.dto.SysRoleDto;
import cn.com.cifi.mars.bean.vo.sys.req.SaveOperGuideReqParam;
import cn.com.cifi.mars.bean.vo.sys.req.UpdateOperGuideReqParam;
import cn.com.cifi.mars.bean.vo.sys.rsp.OperGuideVo;
import cn.com.cifi.mars.bean.vo.sys.rsp.SysRoleVo;
import cn.com.cifi.mars.common.bean.R;
import cn.com.cifi.mars.common.exception.MsgException;
import cn.com.cifi.mars.constant.CodeEnum;
import cn.com.cifi.mars.entity.common.SysOperGuide;
import cn.com.cifi.mars.mapper.mars.SysOperGuideMapper;
import cn.com.cifi.mars.service.SysOperGuideService;
import cn.com.cifi.mars.util.FileUtils;
import cn.com.cifi.mars.util.UUIDUtils;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.util.List;
import java.util.ResourceBundle;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 操作指引表 服务实现类
 * </p>
 *
 * @author yyd
 * @since 2019-11-18
 */
@Service
public class SysOperGuideServiceImpl extends ServiceImpl<SysOperGuideMapper, SysOperGuide> implements SysOperGuideService {

	@Autowired
	private SysOperGuideMapper sysOperGuideMapper;
	
	
	
	/**
	 * 保存上传操作指引
	 */
	@Override
	public int insertOperGuide(SaveOperGuideReqParam param) {
		SysOperGuide bean=new SysOperGuide();
		bean.setFileDesc(param.getFileDesc());
		bean.setFileName(param.getFileName());
		bean.setFileUrl(param.getFileUrl());
		bean.setId(param.getId());
		bean.setCreateTime(LocalDateTime.now());
		bean.setDownloadUrl(param.getDownloadUrl());
		int add=sysOperGuideMapper.insert(bean);
		return add;
	}

	/**
	 * 分页查询操作指引
	 */
	@Override
	public OperGuideVo getOperGuideList(String current,String pageSize) {
		OperGuideVo vo=new OperGuideVo();
		Page<SysRoleDto>pageDto=new Page<>();
		//参数当前页
		pageDto.setCurrent(Integer.parseInt(current));
		//参数每页数量
		pageDto.setSize(Integer.parseInt(pageSize));
		List<OperGuideDto> list=sysOperGuideMapper.selectOperGuideList(pageDto);
		vo.setCurrent(pageDto.getCurrent());
		vo.setPages(pageDto.getPages());
		vo.setPageSize(pageDto.getSize());
		vo.setTotal(pageDto.getTotal());
		vo.setList(list);
		return vo;
	}

	/**
	 * 删除操作指引
	 */
	@Override
	public int deleteOperGuide(String id) {
		return sysOperGuideMapper.deleteById(id);
	}
	
	/**
	 * 编辑上传操作指引
	 */
	@Override
	public int updateOperGuide(UpdateOperGuideReqParam param) {
		SysOperGuide bean=sysOperGuideMapper.selectById(param.getId());
		if(null==bean) {
			throw new MsgException(CodeEnum.SYS_OPER_ERROR);
		}
		bean.setFileDesc(param.getFileDesc());
		bean.setFileName(param.getFileName());
		bean.setFileUrl(param.getFileUrl());
		bean.setDownloadUrl(param.getDownloadUrl());
		bean.setId(param.getId());
		int add=sysOperGuideMapper.updateById(bean);
		return add;
	}

	

}
